import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'home'
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/talk',
    name: 'talk',
    component: () => import( '../views/TalkView.vue')
  },
  {
    path: '/release',
    name: 'release',
    component: () => import( '../views/ReleaseView.vue')
  },
  {
    path: '/find',
    name: 'find',
    component: () => import( '../views/FindView.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import( '../views/MyView.vue'),
    
  },
  {
    path: '/search',
    name: 'search',
    component: () => import( '../views/SearchView.vue')
  },
  {
    path: '/news',
    name: 'news',
    component: () => import( '../views/NewsView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import( '../views/LoginView.vue')
  },
  {
    path: '/details',
    name: 'details',
    component: () => import( '../views/DetailsView.vue')
  },
  {
    path: '/collection',
    name: 'collection',
    component: () => import( '../views/CollectionView.vue')
  },
  {
    path: '/posting',
    name: 'posting',
    component: () => import( '../views/PostingView.vue')
  },
  {
    path: '/myposting',
    name: 'myposting',
    component: () => import( '../views/MypostingView.vue')
  },

]

// 注意:解决路由跳转问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this,location).catch(err=>err);
}


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior() {
    // 始终滚动到顶部
    return { top: 0 }
  },
})

export default router
